//
//  MainTabBarViewCtrl.m
//  DogeLegs
//
//  Created by 宋华 on 2017/8/15.
//  Copyright © 2017年 宋华. All rights reserved.
//

#import "MainTabBarViewCtrl.h"
#import "GlobalConfig.h"
#import "XingViewCtrl.h"
#import "CommunityMainViewCtrl.h"
#import "ChatListViewCtrl.h"
#import "AccountViewCtrl.h"

#import "BaseNavCtrl.h"

@interface MainTabBarViewCtrl () {
    XingViewCtrl *xingCtrl;
    CommunityMainViewCtrl *communityMainCtrl;
    ChatListViewCtrl *chatListCtrl;
    AccountViewCtrl * accountCtrl;
    
    UITabBarItem *xingItem;
    UITabBarItem *communityItem;
    UITabBarItem *chatItem;
    UITabBarItem *acctountItem;
}

@end

@implementation MainTabBarViewCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createTabBarItems];
    [self initMainViewUI];

    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - 初始化界面
- (void)createTabBarItems {
    UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar_bg"];
    //修改tabbar背景图片
    [[UITabBar appearance] setBackgroundImage:tabBarBackground];
    //修改tabbar选中的背景(iOS>7.0 为透明)
    [[UITabBar appearance] setSelectionIndicatorImage:[[UIImage alloc]init]];
    //修改tabbar阴影透明
    [[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
    
    xingItem = [[UITabBarItem alloc] init];
    [xingItem setImageInsets:UIEdgeInsetsMake(3, 0, -3, 0)];
    
    communityItem = [[UITabBarItem alloc] init];
    [communityItem setImageInsets:UIEdgeInsetsMake(3, 0, -3, 0)];
    
    chatItem = [[UITabBarItem alloc] init];
    [chatItem setImageInsets:UIEdgeInsetsMake(-5, 0, 5, 0)];
    
    acctountItem = [[UITabBarItem alloc] init];
    [acctountItem setImageInsets:UIEdgeInsetsMake(3, 0, -3, 0)];
//    //全局配置颜色
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:HEXCOLOR(0x999999), NSForegroundColorAttributeName,nil] forState:UIControlStateNormal];
    
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                       HEXCOLOR(0xff5f1b), NSForegroundColorAttributeName,
                                                       nil] forState:UIControlStateSelected];
    
    [xingItem setImage:[[UIImage imageNamed:@"operateGroupon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [xingItem setSelectedImage:[[UIImage imageNamed:@"operateGrouponHighlighted"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    [communityItem setImage:[[UIImage imageNamed:@"sortNormal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [communityItem setSelectedImage:[[UIImage imageNamed:@"sortHigh"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    [chatItem setImage:[[UIImage imageNamed:@"storeNormal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [chatItem setSelectedImage:[[UIImage imageNamed:@"storeHigh"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

    [acctountItem setImage:[[UIImage imageNamed:@"operateMe"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [acctountItem setSelectedImage:[[UIImage imageNamed:@"operateMeHighLighted"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
}


// 初始化UI
- (void)initMainViewUI
{
    xingCtrl = [[XingViewCtrl alloc] initWithNibName:@"XingViewCtrl" bundle:nil];
    xingCtrl.title = xingItem.title = @"Xing";
    xingCtrl.tabBarItem = xingItem;
    BaseNavCtrl *xingNv = [[BaseNavCtrl alloc] initWithRootViewController:xingCtrl];
    
    communityMainCtrl = [[CommunityMainViewCtrl alloc] initWithNibName:@"CommunityMainViewCtrl" bundle:nil];
    communityItem.title = @"Community";
    communityMainCtrl.title = @"Community";
    communityMainCtrl.tabBarItem = communityItem;
    BaseNavCtrl *communityNav = [[BaseNavCtrl alloc] initWithRootViewController:communityMainCtrl];
    

    chatListCtrl = [[ChatListViewCtrl alloc] initWithNibName:@"ChatListViewCtrl" bundle:nil];
    chatListCtrl.title = @"Chat";
    chatItem.title = @"Chat";
    chatListCtrl.tabBarItem = chatItem;
    BaseNavCtrl *chatNav = [[BaseNavCtrl alloc] initWithRootViewController:chatListCtrl];
    
    
    accountCtrl = [[AccountViewCtrl alloc] initWithNibName:@"AccountViewCtrl" bundle:nil];
    accountCtrl.title = acctountItem.title = @"Account";
    accountCtrl.tabBarItem = acctountItem;
    BaseNavCtrl *accountNav = [[BaseNavCtrl alloc] initWithRootViewController:accountCtrl];
    
    self.viewControllers = @[xingNv, communityNav,chatNav,accountNav];
    self.delegate = self;
}

@end
